home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1045 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: info.uah.edu!oreo!gbacon
  2. From: gbacon@oreo (Greg Bacon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Trouble with file return code.
  5. Date: 11 Jan 1996 03:56:34 GMT
  6. Organization: The University of Alabama in Huntsville
  7. Message-ID: <4d21pj$mi5@info.uah.edu>
  8. References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca>
  9. NNTP-Posting-Host: oreo.aspire.cs.uah.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. xenon@the-fix.sos.on.ca wrote:
  13. :        Im having some trouble getting fread to return NULL when it can't
  14. : find a specific file...
  15.  
  16. :          else if((ptr=fread(filename1,"rb"))!=NULL)
  17. :   {
  18. :        //do this }
  19. :          else    {
  20. :        // do that
  21. :        // this never executes, even if NULL is returned.
  22. : No matter the file, Null is never returned.  Although, when the variable
  23. : ptr is outputed, the value shown is "0".
  24. : thankx
  25. : xenon@the-fix.sos.on.ca
  26.  
  27. I see a few problems with your code:
  28.  
  29. First off, // is not a standard C comment delimiter.  The C Standard states
  30. that /* and */ surround comments.
  31.  
  32. Next, it looks like you're expecting a pointer from fread().  Page 247 of
  33. K&R II gives this prototype for fread():
  34.  
  35. size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream);
  36.  
  37. Oh yeah.. and there's also that technicality of correct ordering of
  38. parameters.  Depending on the implementation, fread() may return 0 on
  39. error or you may have to use feof() and ferror() and determine status.
  40.  
  41. Cheers,
  42. Greg
  43. --
  44. Greg Bacon <gbacon@cs.uah.edu>
  45. University of Alabama in Huntsville
  46. CS Department Systems Support Team
  47.